package com.bawei.lib_base.utils.utils.mvi

import android.app.DatePickerDialog
import android.app.DatePickerDialog.OnDateSetListener
import android.app.TimePickerDialog
import android.os.Bundle
import android.widget.DatePicker
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import java.time.Month
import java.util.*

abstract class BaseActivity<VDB : ViewDataBinding,UiIntent : IUiIntent,VM : BaseViewModel<UiIntent>> : AppCompatActivity(){

    abstract val binding : VDB

    abstract val vm : VM

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        initView()
        initData()
    }

    abstract fun initView()

    abstract fun initData()

    fun showDataDialog(editText: EditText){
        val calendar = Calendar.getInstance()
        DatePickerDialog(this,{view,year,month,dayOfMonth->
            val mon = if (month + 1 < 10) "0${month + 1}" else "${month}"
            val day = if (dayOfMonth < 10) "0${dayOfMonth}" else "$dayOfMonth"
            editText.setText("${year} - ${mon} - ${day}")
        },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)).show()
    }

    fun showTimeDialog(editText: EditText){
        val calendar = Calendar.getInstance()
        TimePickerDialog(this,{view,hourOfDay,minute->
            val hourOfDay = if (hourOfDay + 1 < 10) "0${hourOfDay + 1}" else "${hourOfDay}"
            val minute = if (minute < 10) "0${minute}" else "${minute}:00"
            editText.setText("${hourOfDay}:${minute}")
        },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),true).show()
    }
}